Using Javascript on Websites

Using Javascript on websites is not a new thing. Javascript has been around for quite a while. It gained a bad reputation in the past because hackers would (and still do) include malicous scripts on web pages. Now Javascript is being used beyond the typical applications in the past with the advent of Web 2.0.

Script runtime error

When visiting websites or when using StumbleUpon to find more resoures to share there are a lot of websites that are using javascript that have errors. Even big company websites have these errors. How do I know? Because as a Website Developer, I have scripting error notification turned on to check my own work.

Using Javascipt on a Website Can Create Problems

Search engines don’t read scripts, neither do some of the accessiblity tools used by your surfing challenged visitors.

There are several groups of people who do not use a mouse or pointing device to interact with Web pages. A few examples:

  • Mobility impaired people who cannot use a mouse at all
  • People with motor impairments who can use a mouse but lack fine motor control
  • Screen reader users who do not use a mouse, or even a monitor
  • People using mobile phones
  • Laptop users, since most laptops have really bad trackpads or other means of positioning the cursor (ever tried using a hierarchical dropdown menu with a trackpad while riding on a train?)
  • Speed typers who have learned to use keyboard navigation efficiently and are slowed down when they have to switch to their mouse (if they have one)

Reference: JavaScript interaction must be input device independent

Also, some people surf the web with scripting totally turned off for security reasons or to save on bandwidth.

So, in light of this, do not put really important information in a javascript feature. You’ll be missing a whole section of your website visitors and won’t be adding any valuable content the search engines can see.

Another Reason People Might Not Have Javascript Enabled

Easter weekend 2009 and again the weekend of April 17/09 Twitter was subject to account hacking. Information on how the problem is spread and how to fix your account is available at the following 2 resources. The reason this update was added is, BOTH resources recommend surfing with javascript turned off or using Firefox with the Noscript plugin.

Check Your Javascript Works Without Errors

Before you upload your website complete with javascript, check that the script(s) work properly and do not contain any errors. You can do this by turning on scripting error notification in Internet Explorer or using the javascript debugging tool in Firefox.

Turn on Scripting Error Notification

Turn on scripting error notification while developing your web page(s) if you are going to be using javascript. This is a very useful tool when testing your web pages.

  • Internet Explorer Scripting Error Notification

    To turn on scripting error notification in Internet Explorer:

    1. Left click Tools in the menu bar.
    2. Left click the Internet Options tab.
    3. Left click the Advanced tab.
    4. Under Browsing, find the option

      “Display a notification about every script error”

      If unchecked, then click in the checkbox to turn it on.

    5. Left click Ok at the bottom of the open dialog box and you are done!
  • Javascript Debugging in Firefox

    If you are using Firefox, there is a Firefox Add-on appropriately called JavaScript Debugger available.

Turning on scripting error notification (or using the JavaScript Debugging Firefox Add-on) will help you debug the errors in your javascript.

Why Debug Javascript Errors?

Why debug javascript errors? Because you went to the trouble of using a javascript function or script to add a feature to the website/web page, so you should make sure it works as intended.

Let’s look an example:

Javascript Form Validation

There are javascripts available (or you can write your own) to check that the user has filled out all the parts of your form that are required. They can check that a valid email address was used in the email box, that all the questions that needed answering were answered, and other things like enough/or too many characters entered in the text boxes.

If you upload the form without checking it, how are you going to know it is being validated properly?

When the javascript form validation isn’t working, how are you going to find the scripting errors (beyond the fact it wasn’t written to check what you wanted)?

In comes, scripting error notification.

Scripting Error Notification

With scripting error notification turned on you will see a message from Internet Explorer that there was a scripting error. This message will tell you what line the error was in and what it thinks the error is.

Open up the script file (or web page if hard coded into the page), look for the line noted in the error, and fix it!

Using Javascript on Websites Written by Others

Not everyone knows how to write javascript scripts so there are tonnes of websites that provide predone scripts for you to use as long as you follow their terms of use. Advertising sites, affiliate programs and/or Web 2.0 sites provide scripts for you to use in your web pages also.

If you are going to go this route, test the script in your web page BEFORE uploading the page to a live situation. There’s nothing more annoying than going to a website that doesn’t work properly!

Some scripts may not work when testing locally on your computer e.g. Ajax requires server functionality. In this case, create a testing folder on your webspace (be sure to tell the search engine bots to please stay out) and upload the page/website there for testing.

Testing Javascript Locally

A note to Internet Explorer users who have stricter security settings:

When you test a web page locally that has javascript on it or calls the javascript from an external javascript file, you may get the Internet Explorer yellow security warning bar across the top of the web page. Just right click the yellow bar and allow the script. Annoying when testing but if you are unlikely to remember to turn the feature back on when you are finished testing it’s a small price to pay for internet security.

Using javascript on websites can add great functionality and features to your website, if they work properly. Take the time to test the selected feature/script and debug if necessary before uploading to your live website. You took the time to find and implement a script into the website for the benefit of your website visitors, make sure it works properly!

JavaScript on Websites Additional Reading

Debugging JavaScript: Throw Away Your Alerts! – A look at the throw() statement for detecting script errors.

Screenreaders and JavaScript – “…what it means to use a screen reader, what screen readers are out there and how you can help screen reader users by building your JavaScript applications the right way.”

JavaScript and Screenreaders – How compatilble are your JavaScript events with screenreaders? Read this article to find out. There is a compatibility chart at the end of the article.

JavaScript Tools

JavaScript Lint, you can check all your JavaScript source code for common mistakes without actually running the script or opening the web page.

What's next?

Follow our new articles via RSS, follow us on Twitter and submit to your favourite social networking site:

15 Responses to Using Javascript on Websites

  1. Webmaster Forums Says:

    Finally someone posts the issues WITH the solutions. Great work here. Thanks a bunch.

  2. Quick Connect Says:

    Its a fine line between when to use and when not to use. Most places have learned to always support both, however to advance is to require javascript, thats how browsers are being benchmarked these days, so we just need some security checkups within javascript.

  3. Computer Help Says:

    Javascript errors confuse a lot of Internet surfers.

  4. Peter Moss Says:

    I don’t think Javascript is really a problem. If you serve your Javascript files from your own site then should be ok, assuming you have tested your code in different browsers and versions.

    Problems with Javascript is that most websites link to Javascript on other websites, google, alexa, snap, twitter etc. If the order of inclusion is incorrect or some scripts are missing you end up having a run-time error.
    Other silly thing some site operators do is enable Javascript in comments.

    Normally, any decent site should downgrade gracefully to a mobile version or version that supports older browsers.

    Peter

  5. Kevin Johnson Says:

    I’ve never had any problems with JavaScript. I think the issues arise when people use it and don’t know about javascript. They copy paste the code and don’t know how to fix issues when they arise.

  6. Web Page Mistakes Says:

    That is quite true Kevin. They also don’t test their sites with the NoScript addon in Firefox to see what happens when the user has scripting turned off.

Using Javascript on Websites Was Mentioned Here:

  1. Is Your Blog Accessible?
  2. Media Issues
  3. Browser Specific Design
  4. PHP Editor/IDE
  5. two Javascript items on one page
  6. PopUp HTML Code problems in I.E.8
  7. HTML vs DW
  8. Creating a Website
  9. Website Design

Join the Conversation by Leaving a Reply

You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> within your comment.

By leaving a comment, you acknowledge that you have read our terms of use.